
import java.net.*;
import java.io.*;

public class TCPClient {
	public static void main(String[] args) {
		try {
			Socket so=new Socket("127.0.0.1",8888);
			String s1="";
			String s2="";
			BufferedReader br_j=new BufferedReader(new InputStreamReader(System.in));//键盘入
			OutputStreamWriter osw=new OutputStreamWriter(so.getOutputStream());//socket发
			BufferedReader br_socket=new BufferedReader(new InputStreamReader(so.getInputStream()));//socket收
			BufferedWriter bw=null;
			while((s1=br_j.readLine())!=null){
				bw=new BufferedWriter(osw);
				if(s1.equals("exit")){
					break;
				}
				bw.write(s1);
				bw.write("\r\n");
				bw.flush();
				System.out.println("Client:"+s1);
				if((s2=br_socket.readLine())!=null){
					System.out.println("Server:"+s2);
				}
			}
			bw.close();
			br_socket.close();
			br_j.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
